package com.reds.backend.controller.homeArticle;

import com.alibaba.fastjson2.JSONObject;
import com.reds.backend.pojo.Article;
import com.reds.backend.utils.adminUtils.admin.StpAdminUtil;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.reds.backend.service.homeArticle.homeArticleCRUDService;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/homeArticle")
public class homeArticleCRUDController {
    @Autowired
    homeArticleCRUDService homeArticleCRUDService;
    @PostMapping("/updataShowHome/")
    public String addNewShowHomeByTag(@RequestParam Map<String,String> map){
        StpAdminUtil.checkRole("superAdmin");
        return homeArticleCRUDService.updataShowHome(Integer.parseInt(map.get("id")),Integer.parseInt(map.get("aid")));
    }
    @PostMapping("/deteleShowHome/")
    public String deteleShowHome(@RequestParam Map<String,String> map){
        StpAdminUtil.checkRoleOr("superAdmin");
        return homeArticleCRUDService.deteleShowHome(Integer.parseInt(map.get("id")));
    }
    @PostMapping("/getShowHomeByTag/")//按照tag不同返回首页展示
    public JSONObject getShowHomeByTag(@RequestParam Map<String,String> map){
        return homeArticleCRUDService.getShowHomeByTag(map.get("tag"));
    }
}
